{% extends "base.html" %} {# Django wants this first, even before comments #}

{% comment %}
Copyright 2012 Google Inc.  All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.  You may obtain a copy
of the License at: http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distrib-
uted under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
OR CONDITIONS OF ANY KIND, either express or implied.  See the License for
specific language governing permissions and limitations under the License.
{% endcomment %}

{% block navbar %}
  <div class="cm-button-area">
    <form method="post" action="/crisismap/create">
      <input type="submit" class="cm-create cm-button"
          title="Create a new map" value="Create map">
    </form>
  </div>
  {{block.super}}
{% endblock navbar %}

{% block content %}
  <table class="cm-map-list">
    <tr>
      <th colspan=4 class="cm-map-list-header">Maps you can view</th>
    </tr>
    <tr>
      <th>Draft Version</th>
      <th>Created</th>
      <th>Last updated</th>
      <th>Map Operations</th>
      <th>Published Version</th>
    </tr>
    {% for m in maps %}
      <tr>
        <td><a href="maps/{{m.id}}" title="{{m.description}}"
            >{{m.title}}</a></td>
        <td>{{m.created|timesince}} ago by {{m.creator}}</td>
        <td>{{m.last_updated|timesince}} ago by {{m.last_updater}}</td>
        <td>
          <form action="/crisismap/delete" method="post">
            <input name="map_id" type=hidden value="{{m.id}}">
            <input type=submit value="Delete Map">
          </form>
        </td>
        <td class="cm-publish-status">
          {% for e in m.catalog_entries %}
            <div>
              <a href="/crisismap/a/{{e.domain}}/{{e.label}}">
                {{e.domain}}/{{e.label}}
              </a>
              <span class="cm-publish-age">
                {{e.last_updated|timesince}} ago
                {% ifequal e.map_version_id m.GetCurrent.id %}
                  (up to date)
                {% else %}
                  (out of date)
                {% endifequal %}
              </span>
              {% if e.domain in publishing_domains %}
                {% ifnotequal e.map_version_id m.GetCurrent.id %}
                  <form action="/crisismap/publish" method="post">
                    <input name="label" type=hidden value="{{e.label}}">
                    <input name="map_id" type=hidden value="{{m.id}}">
                    <input name="domain" type=hidden value="{{e.domain}}">
                    <input type=submit value="Republish">
                  </form>
                {% endifnotequal %}
                <form action="/crisismap/unpublish" method="post">
                  <input name="domain" type=hidden value="{{e.domain}}">
                  <input name="label" type=hidden value="{{e.label}}">
                  <input type=submit value="Unpublish">
                </form>
              {% endif %}
            </div>
          {% endfor %}
          {% if publishing_domains %}
            <form action="/crisismap/publish" method="post">
              <select name="domain">
                {% for domain in publishing_domains %}
                  <option value="{{domain}}">{{domain}}</option>
                {% endfor %}
              </select>
              <input name="label" size=20>
              <input name="map_id" type=hidden value="{{m.id}}">
              <input type=submit value="Publish">
            </form>
          {% endif %}
      </tr>
    {% endfor %}
  </table>
{% endblock content %}
